<template>
	<view class="news-detail">
		<!-- 头部导航 -->
		<view class="header">
			<view class="nav-bar">
				<view class="nav-left" @click="goBack">
					<image src="/static/images/back.png" class="back-icon"></image>
				</view>
				<view class="nav-title">新闻详情</view>
				<view class="nav-right" @click="shareNews">
					<image src="/static/images/share.png" class="share-icon"></image>
				</view>
			</view>
		</view>
		
		<!-- 新闻内容 -->
		<view class="news-content" v-if="newsDetail">
			<!-- 新闻标题 -->
			<view class="news-title">{{ newsDetail.title }}</view>
			
			<!-- 新闻元信息 -->
			<view class="news-meta">
				<view class="meta-left">
					<view class="publish-time">{{ newsDetail.publishTime }}</view>
					<view class="category-tag" :class="'tag-' + newsDetail.category">
						{{ getCategoryName(newsDetail.category) }}
					</view>
				</view>
				<view class="meta-right">
					<view class="views-count">
						<image src="/static/images/eye.png" class="eye-icon"></image>
						<text>{{ newsDetail.views }}</text>
					</view>
				</view>
			</view>
			
			<!-- 新闻图片 -->
			<view class="news-image" v-if="newsDetail.image">
				<image :src="newsDetail.image" mode="aspectFill" class="image"></image>
			</view>
			
			<!-- 新闻正文 -->
			<view class="news-body">
				<rich-text :nodes="newsDetail.content"></rich-text>
			</view>
			
			<!-- 相关新闻 -->
			<view class="related-news" v-if="relatedNews.length > 0">
				<view class="section-title">相关新闻</view>
				<view class="related-list">
					<view 
						class="related-item" 
						v-for="item in relatedNews" 
						:key="item.id"
						@click="goToRelated(item)"
					>
						<image :src="item.image" mode="aspectFill" class="related-image"></image>
						<view class="related-content">
							<view class="related-title">{{ item.title }}</view>
							<view class="related-time">{{ item.publishTime }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 底部操作栏 -->
		<view class="bottom-actions">
			<view class="action-item" @click="toggleLike">
				<image 
					:src="isLiked ? '/static/images/like-filled.png' : '/static/images/like.png'" 
					class="action-icon"
				></image>
				<text class="action-text">{{ isLiked ? '已赞' : '点赞' }}</text>
			</view>
			<view class="action-item" @click="toggleCollect">
				<image 
					:src="isCollected ? '/static/images/collect-filled.png' : '/static/images/collect.png'" 
					class="action-icon"
				></image>
				<text class="action-text">{{ isCollected ? '已收藏' : '收藏' }}</text>
			</view>
			<view class="action-item" @click="shareNews">
				<image src="/static/images/share.png" class="action-icon"></image>
				<text class="action-text">分享</text>
			</view>
		</view>
		
		<!-- 加载状态 -->
		<view class="loading" v-if="loading">
			<text>加载中...</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			newsId: '',
			loading: true,
			isLiked: false,
			isCollected: false,
			newsDetail: null,
			relatedNews: [
				{
					id: 2,
					title: '年度总结大会成功召开',
					image: '/static/images/news2.jpg',
					publishTime: '2024-01-10'
				},
				{
					id: 3,
					title: '员工培训计划正式启动',
					image: '/static/images/news3.jpg',
					publishTime: '2024-01-08'
				}
			]
		}
	},
	onLoad(options) {
		this.newsId = options.id
		this.loadNewsDetail()
	},
	methods: {
		// 加载新闻详情
		loadNewsDetail() {
			this.loading = true
			// 模拟API调用
			setTimeout(() => {
				this.newsDetail = {
					id: this.newsId,
					title: '公司新产品发布，引领行业创新',
					summary: '公司最新产品系列正式发布，涵盖多个行业应用场景，为客户提供更优质的解决方案。',
					image: '/static/images/news1.jpg',
					category: 'company',
					publishTime: '2024-01-15',
					views: 1256,
					content: `
						<p>公司最新产品系列正式发布，这一重大突破标志着我们在技术创新方面又迈出了重要一步。</p>
						<p>新产品具有以下特点：</p>
						<ul>
							<li>采用最新的AI技术，提升用户体验</li>
							<li>支持多平台部署，满足不同客户需求</li>
							<li>安全性大幅提升，保障数据安全</li>
							<li>性能优化，响应速度提升50%</li>
						</ul>
						<p>我们相信，这款产品将为客户带来更大的价值，推动整个行业的发展。</p>
						<p>未来，我们将继续加大研发投入，推出更多创新产品，为客户提供更优质的服务。</p>
					`
				}
				this.loading = false
			}, 1000)
		},
		
		// 获取分类名称
		getCategoryName(category) {
			const categories = {
				'company': '公司动态',
				'industry': '行业资讯',
				'policy': '政策解读',
				'technology': '技术前沿'
			}
			return categories[category] || '未知'
		},
		
		// 返回上一页
		goBack() {
			uni.navigateBack()
		},
		
		// 分享新闻
		shareNews() {
			uni.showActionSheet({
				itemList: ['分享到微信', '分享到朋友圈', '复制链接'],
				success: (res) => {
					console.log('分享选项:', res.tapIndex)
					// 处理分享逻辑
				}
			})
		},
		
		// 切换点赞状态
		toggleLike() {
			this.isLiked = !this.isLiked
			uni.showToast({
				title: this.isLiked ? '点赞成功' : '取消点赞',
				icon: 'none'
			})
		},
		
		// 切换收藏状态
		toggleCollect() {
			this.isCollected = !this.isCollected
			uni.showToast({
				title: this.isCollected ? '收藏成功' : '取消收藏',
				icon: 'none'
			})
		},
		
		// 跳转到相关新闻
		goToRelated(news) {
			uni.navigateTo({
				url: `/pages/news/detail?id=${news.id}`
			})
		}
	}
}
</script>

<style scoped>
.news-detail {
	background: #ffffff;
	min-height: 100vh;
	padding-bottom: 120rpx;
}

/* 头部导航 */
.header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 100;
	background: #ffffff;
	border-bottom: 1rpx solid #f0f0f0;
}

.nav-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 88rpx;
	padding: 0 30rpx;
	padding-top: var(--status-bar-height);
}

.nav-left, .nav-right {
	width: 60rpx;
	height: 60rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.back-icon, .share-icon {
	width: 36rpx;
	height: 36rpx;
}

.nav-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
}

/* 新闻内容 */
.news-content {
	padding: 30rpx;
	margin-top: 88rpx;
}

.news-title {
	font-size: 36rpx;
	font-weight: bold;
	color: #333333;
	line-height: 1.4;
	margin-bottom: 30rpx;
}

.news-meta {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 30rpx;
	padding-bottom: 20rpx;
	border-bottom: 1rpx solid #f0f0f0;
}

.meta-left {
	display: flex;
	align-items: center;
}

.publish-time {
	font-size: 24rpx;
	color: #999999;
	margin-right: 20rpx;
}

.category-tag {
	padding: 6rpx 12rpx;
	border-radius: 12rpx;
	font-size: 22rpx;
	color: #ffffff;
}

.tag-company {
	background: #667eea;
}

.tag-industry {
	background: #f093fb;
}

.tag-policy {
	background: #4facfe;
}

.tag-technology {
	background: #43e97b;
}

.meta-right {
	display: flex;
	align-items: center;
}

.views-count {
	display: flex;
	align-items: center;
	font-size: 24rpx;
	color: #999999;
}

.eye-icon {
	width: 24rpx;
	height: 24rpx;
	margin-right: 8rpx;
}

.news-image {
	margin-bottom: 30rpx;
	border-radius: 12rpx;
	overflow: hidden;
}

.image {
	width: 100%;
	height: 400rpx;
}

.news-body {
	font-size: 28rpx;
	line-height: 1.6;
	color: #333333;
}

.news-body p {
	margin-bottom: 20rpx;
}

.news-body ul {
	margin: 20rpx 0;
	padding-left: 40rpx;
}

.news-body li {
	margin-bottom: 10rpx;
}

/* 相关新闻 */
.related-news {
	margin-top: 60rpx;
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
	margin-bottom: 30rpx;
}

.related-list {
	background: #f5f7fa;
	border-radius: 16rpx;
	padding: 20rpx;
}

.related-item {
	display: flex;
	background: #ffffff;
	border-radius: 12rpx;
	padding: 20rpx;
	margin-bottom: 15rpx;
	transition: transform 0.3s ease;
}

.related-item:last-child {
	margin-bottom: 0;
}

.related-item:active {
	transform: scale(0.98);
}

.related-image {
	width: 120rpx;
	height: 80rpx;
	border-radius: 8rpx;
	margin-right: 20rpx;
}

.related-content {
	flex: 1;
}

.related-title {
	font-size: 26rpx;
	color: #333333;
	line-height: 1.4;
	margin-bottom: 10rpx;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.related-time {
	font-size: 22rpx;
	color: #999999;
}

/* 底部操作栏 */
.bottom-actions {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: #ffffff;
	border-top: 1rpx solid #f0f0f0;
	padding: 20rpx 30rpx;
	padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
	display: flex;
	justify-content: space-around;
}

.action-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 10rpx 20rpx;
	border-radius: 12rpx;
	transition: background-color 0.3s ease;
}

.action-item:active {
	background: #f5f7fa;
}

.action-icon {
	width: 40rpx;
	height: 40rpx;
	margin-bottom: 8rpx;
}

.action-text {
	font-size: 22rpx;
	color: #666666;
}

/* 加载状态 */
.loading {
	text-align: center;
	padding: 100rpx 0;
	font-size: 28rpx;
	color: #999999;
}
</style>
